<!-- TipType 影城提示文本 -->
<template>
  <view :class="customClass" class="main">
    <view v-for="(item, index) in tagList" :key="index">
      <view
        v-if="item.tagType === '1'"
        class="icon mr10 flex-c-m mb10"
        :style="[getTagStyle(item)]"
        ><view>{{ item.tagContent }}</view></view
      >
      <image
        v-else
        class="flex-c-m"
        style="height: 30rpx; margin-right: 10rpx; margin-bottom: 10rpx"
        mode="heightFix"
        :src="item.tagContent"
      ></image>
      <!-- <zm-image :src="item.tagContent" height="30rpx"></zm-image> -->
    </view>
  </view>
</template>

<script>
  import ZmImage from '@/commons/ZmImage/index.vue'
  export default {
    name: 'tip-type',
    components: { ZmImage },
    props: {
      customClass: {
        type: String
      },
      tagList: {
        type: Array,
        default: () => {
          return []
        }
      },
      value: {
        type: String
      }
    },
    data() {
      return {}
    },
    created() {
      this.getData()
    },
    computed: {
      getTagStyle() {
        return (item) => {
          let style = ''
          if (item.tagStyle === '1') {
            style = {
              background: `linear-gradient(135deg, ${item.tagColorSet.startColor} 0%, ${item.tagColorSet.endColor} 100%)`,
              border: 'none',
              color: '#fff'
            }
          } else {
            style = {
              color: item.tagColor,
              borderColor: item.tagColor
            }
          }
          return style
        }
      }
    },
    methods: {
      getData() {
        // 获取数据后传入图片url获取尺寸(宽高)
        // this.tagList.map(async (item) => {
        //   if (item.tagType === '2') {
        //     item.imgSize = await this.getImgSize(item.tagContent)
        //   }
        // })
        // this.tagList = [...this.tagList, ...this.tagList]
        console.log('this.tagList', this.tagList)
      },
      // 获取图片尺寸
      getImgSize(url) {
        return new Promise((resolve, reject) => {
          const imgObj = new Image()
          imgObj.src = url
          imgObj.onload = () => {
            resolve({
              width: imgObj.width,
              height: imgObj.height
            })
          }
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .main {
    display: flex;
    flex-direction: row;
    align-items: center;
    white-space: nowrap;
    // overflow-x: scroll;
    flex-wrap: wrap;
    .icon {
      border-radius: 8rpx;
      border-width: 1rpx;
      border-style: solid;
      font-size: 18rpx;
      height: 30rpx;
      line-height: 18rpx;
      padding: 0 10rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 10rpx;
      box-sizing: border-box;
    }
  }
</style>
